package com.demo.springbootdemo.mapper;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.demo.springbootdemo.domain.po.User;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface UserMapper extends BaseMapper<User> {
    public List<User> testXmlDefineSql();

    // 注意wrapper的参数名注解必须是ew
    public void updateBalanceByIds(@Param(Constants.WRAPPER) LambdaQueryWrapper<User> wrapper, @Param("amount") int amount);

    @Update("update user set balance = balance - #{amount} ${ew.customSqlSegment}")
    public void updateBalanceByIdsAnnotation(@Param(Constants.WRAPPER) LambdaQueryWrapper<User> wrapper, @Param("amount") int amount);

    @Update("update user set balance = balance - #{money} where id = #{id}")
    public void deductById(@Param("id") Long id, @Param("money") int money);
}
